﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Cfg;
using NHibernate;
using FluentNHibernate;
using System.Data;
using FluentNHibernate.Cfg.Db;
using Noodles.Core.Model;
using FluentNHibernate.Cfg;

  namespace Noodles.Core.Repositories
 {
     public class NHibernateHelper
      {
       private static ISessionFactory _sessionFactory;

       private static ISessionFactory SessionFactory
       {
           get
           {
               if (_sessionFactory == null)
              {
                   var configuration = new Configuration();   
                   _sessionFactory= Fluently.Configure()
                       .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromAppSetting("FluentNHibernateConnection")))
                       .Mappings(m =>
                       {
                           // Include both standard NHibernate mapping files and Fluent NHibernate mapping files
                           m.HbmMappings.AddFromAssemblyOf<Categories>();
                           m.FluentMappings.AddFromAssemblyOf<Post>();
                       })
                       .BuildSessionFactory();

              }
               return _sessionFactory;
           }
       }         
   
 
         public static ISession OpenSession()
         {
            return SessionFactory.OpenSession();
         }
   }
 }
